#ifndef COMMON_HEADER
#define COMMON_HEADER

#define bool char
#define true 1
#define false 0


#include <WinSock2.h>



#define MAXBUFFSIZE 64
#define MAXCONN 10
#define PORT "12345"
#define PORT1 "22345"
#define PORT2 "32345"
#define PORT3 "42345"
#define LOCALHOST "127.0.0.1"

#define USER_CONNECT 0
#define USER_RELEASE 1
#define USER_GETNODE 2
#define NODE_GETNUM 3

typedef struct _TOperationInfo {
	int op;
	int val;
} TOperationInfo;

typedef struct _TSocketInfo {
	WSAOVERLAPPED overlapped;
	ULONG recvBytes;
	ULONG flag;
	WSABUF buf;
	char internalBuffer[MAXBUFFSIZE];
} TSocketInfo;

typedef int KEYTYPE;

typedef struct _TUserInfo {
	KEYTYPE id;
	void* param;
	struct _TUserInfo* father;
	struct _TUserInfo* left;
	struct _TUserInfo* right;
} TUserInfo;

TUserInfo* tUserInfo(KEYTYPE id);
TSocketInfo* tSocketInfo(void);


/*
void error(char* msg);

SOCKET createListenSocket(char* port, SOCKET* inSocket, bool block);
SOCKET createConnectSocket(char* port, char* ipaddr, SOCKET* inSocket);
//*/
bool addUser(TUserInfo* root, KEYTYPE id, TUserInfo** rootUser);
bool deleteUser(TUserInfo* root, KEYTYPE id, TUserInfo** rootUser);
bool find(TUserInfo* root, KEYTYPE id, TUserInfo** rootUser);



#endif